#!/usr/bin/env ruby
# SPDX-License-Identifier: MulanPSL-2.0+
# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
# frozen_string_literal: true

require 'set'
require_relative '../defconfig.rb'

names = Set.new %w[
  SCHED_PORT
  git.cbs
  git.compass-ci
  git.lkp-tests
]
defaults = relevant_defaults(names)

SCHED_PORT = (defaults['SCHED_PORT'] || '3000')

docker_skip_rebuild "sch-ruby-a:v0.00d-#{SCHED_PORT}"

%w(lkp-tests compass-ci cbs).each do |repo|
  download_repo(repo, defaults["git." + repo])
end

CCI_SRC = ENV['CCI_SRC']
system("bash #{CCI_SRC}/container/compile .") || exit
system "cp #{CCI_SRC}/sbin/create-job-cpio.sh ."

system "docker build --no-cache -t sch-ruby-a:v0.00d-#{SCHED_PORT} ."

push_image_remote "sch-ruby-a:v0.00d-#{SCHED_PORT}"

system 'rm scheduler'
system 'rm create-job-cpio.sh'
